/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.acq.web.userarea;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.acq.entity.userarea.AcqUserArea;
import com.thinkgem.jeesite.modules.acq.service.userarea.AcqUserAreaService;

/**
 * 区域录入员管理Controller
 * @author lj
 * @version 2018-05-01
 */
@Controller
@RequestMapping(value = "${adminPath}/acq/userarea/acqUserArea")
public class AcqUserAreaController extends BaseController {

	@Autowired
	private AcqUserAreaService acqUserAreaService;
	
	@ModelAttribute
	public AcqUserArea get(@RequestParam(required=false) String id) {
		AcqUserArea entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = acqUserAreaService.get(id);
		}
		if (entity == null){
			entity = new AcqUserArea();
		}
		return entity;
	}
	
	@RequiresPermissions("acq:userarea:acqUserArea:view")
	@RequestMapping(value = "index")
	public String index(AcqUserArea acqUserArea, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<AcqUserArea> page = acqUserAreaService.findPage(new Page<AcqUserArea>(request, response), acqUserArea); 
		model.addAttribute("page", page);
		return "modules/acq/userarea/acqUserAreaIndex";
	}
	
	
	@RequiresPermissions("acq:userarea:acqUserArea:view")
	@RequestMapping(value = {"list", ""})
	public String list(AcqUserArea acqUserArea, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<AcqUserArea> page = acqUserAreaService.findPage(new Page<AcqUserArea>(request, response), acqUserArea); 
		model.addAttribute("page", page);
		return "modules/acq/userarea/acqUserAreaList";
	}

	@RequiresPermissions("acq:userarea:acqUserArea:view")
	@RequestMapping(value = "form")
	public String form(AcqUserArea acqUserArea, Model model) {
		model.addAttribute("acqUserArea", acqUserArea);
		return "modules/acq/userarea/acqUserAreaForm";
	}

	@RequiresPermissions("acq:userarea:acqUserArea:edit")
	@RequestMapping(value = "save")
	public String save(AcqUserArea acqUserArea, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, acqUserArea)){
			return form(acqUserArea, model);
		}
		acqUserAreaService.save(acqUserArea);
		addMessage(redirectAttributes, "保存区域录入员管理成功");
		return "redirect:"+Global.getAdminPath()+"/acq/userarea/acqUserArea/?repage";
	}
	
	@RequiresPermissions("acq:userarea:acqUserArea:edit")
	@RequestMapping(value = "delete")
	public String delete(AcqUserArea acqUserArea, RedirectAttributes redirectAttributes) {
		acqUserAreaService.delete(acqUserArea);
		addMessage(redirectAttributes, "删除区域录入员管理成功");
		return "redirect:"+Global.getAdminPath()+"/acq/userarea/acqUserArea/?repage";
	}

}